﻿namespace KinonekoSoftware.Studio.Resources.Converters
{
    public class CoverConverter: ImageConverterBase<MusicSystem>
    {
        private static readonly BitmapImage DefaultImage = new BitmapImage(new Uri(URI_IMAGE_COVER));

        protected override ImageSource GetFallbackImage() => DefaultImage;
        
        /// <summary>
        /// 根据指定的ID获取图片。
        /// </summary>
        /// <param name="id">图片的ID</param>
        /// <returns>返回指定ID所对应的图片或者返回回滚图片。</returns>
        protected override ImageSource GetImage(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return GetFallbackImage();
            }

            var stream = GetStream(id);
            if (stream is null)
            {
                return GetFallbackImage();
            }
            return GetImage(id, stream);
        }
    }
}